% clc;
% close all;

image = imread('lena.pgm');

%creation du filtre avec la fonction butter
%filter = butter(3, .1);

[rows,cols] = size(image);

%creation de la matrice radius
xrange = [-cols/2:(cols/2-1)];
yrange = [-rows/2:(rows/2-1)];
[x,y] = meshgrid(xrange,yrange);
radius = sqrt(x.^2 + y.^2);

%affectation des parametres
Do = 10;
n = 2;

%creation du filtre de Butterworth
filter = 1 ./ (1+((radius./Do).^(2*n)));

%creation de la transformation de fourier et centrage de celle-ci
image_ft = fftshift(fft2(double(image)));

%filtrage de notre image
image_filtered = image_ft .* filter;

%module de l'image
image_mod = log(1+abs(image_filtered));

%decentrage et transformee de Fourier inverse
image_ift = ifft2(ifftshift(image_filtered));

subplot(1,3,1);
imshow(image);
title('Originale');

subplot(1,3,2);
imagesc(image_mod);
title('Module');

subplot(1,3,3);
imagesc(image_ift);
title('Transformee de Fourier inverse');